package utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;

public class LocationUtils {

    public static String getLocFromList(String locField){
        BufferedReader locReader = null;
        try {
            locReader = Files.newBufferedReader(Paths.get("D:\\locations.txt"), Charset.forName("UTF-8"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        List<String> locList = locReader.lines().collect(Collectors.toList());
        List<String> resList  = locList.stream()
                .filter( loc -> locField.startsWith(loc))
                .collect(Collectors.toList());
        if ( resList.size() >=1)
            return resList.get(0);
        else
            return "unknown";
    }

}
